﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace PlaylistGenerator_v2._0
{
    public class GeradorDeXml
    {
        private static XmlTextWriter xr;

        public static void geraXml(String fileName, List<Pasta> pastas)
        {
            xr = new XmlTextWriter(fileName, Encoding.UTF8);
            xr.Formatting = Formatting.Indented;
            xr.WriteStartDocument();
            xr.WriteStartElement("mediaPlayer");
            foreach (Pasta pasta in pastas)
            {
                xr.WriteStartElement("pasta");
                adicionaAtributo("nomeDaPasta", pasta.NomeDaPasta);
                adicionaAtributo("folderPath", pasta.FolderPath);
                adicionaAtributo("tipoDePasta", pasta.Tipo.ToString());
                xr.WriteEndElement();
            }
            xr.WriteEndElement();
            finalizaArquivo();
        }

        private static void adicionaAtributo(String nome, String valor)
        {
            xr.WriteStartAttribute(nome);
            xr.WriteString(valor);
            xr.WriteEndAttribute();
        }

        private static void finalizaArquivo()
        {
            xr.WriteEndDocument();

            xr.Flush();
            xr.Close();
        }

        
    }
}
